class CompaniesController < ApplicationController
  skip_before_filter :require_login, :only => [:get_all]
  
  def create
    @company = Company.new(:name => params[:name])
    if @company.save
      rtn_json({'name'=>@company.name,'id'=>@company.id, 'status' => '200'})
    else
      rtn_json({'error' => 'Could not create Company'})  
    end    
  end
  
  def get_all
    @companies = Company.all()
    result = {}
    
    if @companies
      rtn_json(@companies)
    else
      rtn_json('error' => 'Error. Could not get all companies')
    end
  end
  
  def rtn_json(obj)
    respond_to do |format|
      format.html{render json: obj, :callback => params[:callback]}
      format.json{render json: obj, :callback => params[:callback]}
    end
  end
end
